<?php
namespace Home\Model;
use Think\Model;
class UserModel extends Model{
     protected $_validate=array(
	 	   array('username','require','用户名必须写'),
	 	   array('username','','用户名重复',0,'unique'),
	 	   array('username','2,20','用户名长度在4-20位',1,'length'),
	 	   array('password','require','密码必须填写'),
	 	   array('password','6,20','密码长度在6-20位',1,'length'),
       array('password','repass','两个密码不一致',0,'confirm'),
       array('mobile','/^1[3|4|5|8][0-9]{9}$/','手机格式不对','regex'),
       array('email','email','邮箱格式不对',1),
       array('verify','check_verify','验证码不对',1,'callback'),
       array('name','require','用户名必须写'),
       array('pass','require','密码必须写')
	 	);
	 protected $_auto=array(
	 	    array('realname','未知'),
	 	    array('add_time','time',1,'function'),
	 	    array('password','md5',1,'function')
	 	     //1.添加 2.修改 
	 	);
   public  function check_verify($code, $id = ''){    
    	$verify = new \Think\Verify();    
    	return $verify->check($code, $id);
    }
   public  function checkLogin($arr){
    	$where['username']=$arr['username'];
    	$where['password']=$arr['password'];
      $result=$this->where($where)
                     ->select();
      return $result;
    }
    public function updateUserInfo($id,$data){
        $result=$this->where('id='.$id)
                     ->save($data);
        return $result;       
    }
    public function uploadHead($id,$string){
        $where['id']=$id;
        $data['head_img']=$string;
        $result=$this->where($where)
                     ->save($data);
        return $result;
    }
}